package com.my.java8;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

public class FactoryExample {

	public interface TriFunction<T, U, V, R> {
		R apply(T t, U u, V v);
	}

	static class Product {

	}

	static class Loan extends Product {

	}

	static class Stock extends Product {

	}

	static class Bond extends Product {

	}

	final static Map<String, Supplier<Product>> map = new HashMap<>();
	Map<String, TriFunction<Integer, Integer, String, Product>> map3 = new HashMap<>();
	
	static {
		map.put("loan", Loan::new);
		map.put("stock", Stock::new);
		map.put("bond", Bond::new);
	}

	public static Product createProduct(String name) {
		Supplier<Product> p = map.get(name);
		if (p != null)
			return p.get();
		throw new IllegalArgumentException("No such product " + name);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
